package com.by.auto;

import com.by.interceptor.TokenInterceptor;
import com.by.interceptor.TokenWebConfig;
import com.by.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * date 2025/2/12 17:53
 * author bjj
 * decoration
 * version 1.0
 * since jdk11
 */
@AutoConfiguration
@EnableConfigurationProperties(TokenInterceptorProperties.class)
@ConditionalOnClass(value = {TokenInterceptor.class, TokenWebConfig.class})
@ConditionalOnProperty(prefix = "token.interceptor",name = "enabled",matchIfMissing = true)
public class TokenInterceptorAutoConfigure {
    @Bean
    public WebMvcConfigurer webMvcConfigurer(TokenInterceptorProperties properties, TokenTemplate tokenTemplate) {
        TokenWebConfig webConfig = new TokenWebConfig(properties, tokenTemplate);
        return webConfig;
    }
}
